package com.itita.ww2.model.user;

import com.google.gson.GsonBuilder;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.itita.ww2.data.PlayerConfig;
import com.itita.ww2.utils.TimeUtil;

public class UserFatigue {
	private int fatigue; // 疲劳值
	private int ffCount; // 当天补满疲劳次数
	private long lastFFTime; // 上次补充时间

	// 
	public int getFatigue() {
		return fatigue;
	}

	public void setFatigue(int fatigue) {
		this.fatigue = fatigue;
	}

	public int getFfCount() {
		return ffCount;
	}

	public long getLastFFTime() {
		return lastFFTime;
	}

	public void setLastFFTime(long lastFFTime) {
		this.lastFFTime = lastFFTime;
	}

	public void addFfCount() {
		this.ffCount++;
	}
	
	public void resetFfCount(){
		this.ffCount = 0;
	}

	public static UserFatigue newFromJsonData(String json) {
		UserFatigue ret = new GsonBuilder().create().fromJson(json, UserFatigue.class);
		if (TimeUtil.isFatigueReset(ret.lastFFTime, PlayerConfig.getFatigueResetTimeZone(),
				PlayerConfig.getFatigueResetTimeLine())) {
			ret.lastFFTime = 0;
			ret.ffCount = 0;
		}
		return ret;
	}

	public ISFSObject toSFSObject() {
		return SFSObject.newFromJsonData(new GsonBuilder().create().toJson(this));
	}
}
